package com.syt.cellphone.information.http

import com.syt.cellphone.information.http.HttpHelper.next
import kotlinx.coroutines.flow.flow

/**
 * @author       zhulei
 * @data         2021/1/11 14:15
 * @function    请求的所有
 */
object RequestHelp {

    /**
     * 分页查询
     */
    suspend fun getBaseListPhone(pageNumber: Int) = flow {
        val response = HttpHelper.getApiService(MyApi::class.java).getBaseListPhone(pageNumber)
        val data = HttpHelper.checkError(response)
        emit(data)
    }.next()

    /**
     * 搜索
     */
    suspend fun getClassifyPhone(pageNumber: Int, searchString: String) = flow {
        val response = HttpHelper.getApiService(MyApi::class.java).getClassifyPhone(pageNumber, searchString)
        val data = HttpHelper.checkError(response)
        emit(data)
    }.next()

    /**
     * 查询详情
     */
    suspend fun getPhoneDetailsById(phoneId: String) = flow {
        val response = HttpHelper.getApiService(MyApi::class.java).getPhoneDetailsById(phoneId)
        val data = HttpHelper.checkError(response)
        emit(data)
    }.next()

}